package com.guchenbo.example.thread;

public class T2 {

	public static void main(String[] args) {
		System.out.println(Thread.currentThread().getName());

		ThreadGroup group = Thread.currentThread().getThreadGroup();
		ThreadGroup topGroup = null;
		// 取得此线程组的顶级父线程
		while ((group = group.getParent()) != null)
			topGroup = group;

		// 将有关此线程组的信息打印到标准输出
		topGroup.list();

		// activeCount() 返回此线程组中活动线程的估计数
		Thread[] threads = new Thread[topGroup.activeCount() * 2];
		// 把此线程组及其子组中的所有活动线程复制到指定数组中
		topGroup.enumerate(threads);
		// 遍历格式化输处所有线程信息
		System.out.format("%-20s%-20s%-20s%n", "ThreadGroupName", "ThreadName", "Priority");
		for (Thread thread : threads)
			if (thread != null && thread.isAlive())
				System.out.format("%-20s%-20s%-20s%n", thread.getThreadGroup().getName(), thread.getName(),
						thread.getPriority());

	}
}
